﻿@{
    ViewBag.Title = "Management";
}
<script>
    $(document).ready(function () {
        //        $("button[name=Create]").click(function () {
        //            window.location = '@Url.Action("Create", "Discussion", new { subjectId = @ViewBag.SubjectId })';
        //        });

    });

    function active(element, id) {
        switch (id) {
        case "my":
            $.ajax({
                url: '@Url.Action("Management", "Discussion", new { userId = int.Parse(HttpContext.Current.User.Identity.Name) })',
                type: 'GET',
                success: function(data) {
                    $("#unobtrusive").html(data);
                }
            });
            break;
        case "all":
            $.ajax({
                url: '@Url.Action("Management", "Discussion")',
                type: 'GET',
                success: function(data) {
                    $("#unobtrusive").html(data);
                }
            });
            break;
        default:
            var txtSearch = $("#txtsearch").val();
            $.ajax({
                url: './Management?keyWord=' + txtSearch,
                type: 'GET',
                success: function(data) {
                    $("#unobtrusive").html(data);
                }
            });
        }

        $("button").removeClass('active');
        $("#spansearch").hide();
        if (id == "btnsearch") {
            $("#spansearch").show();
            $("#search").addClass('active');
        } else {
            $(element).addClass('active');
        }
    }
</script>
<div class="site_map">
    @Html.ActionLink("Home", "Index", "Home", new {Area = ""}, new {})
    / Discussion Management
</div>
<br />
<div class="row" style="height: 50px">
    <div class="span3">
        <button class="btn" type="button" name="Create">
            <i class="icon-plus"></i>
            Start a new Discussion
        </button>
    </div>
    <div class="span12" style="text-align: right">
        <input type="text" id="txtsearch" placeholder="Title of Discussion" class="input-xlarge search-query"/>
        <button type="button" id="btnsearch" class="btn" onclick="active($(this), this.id)">Search</button>
    </div>
</div>
<div class="row">
    <div class="span3">
        <table class="table table-bordered">
            <thead>
                <tr style="background-color: #F5F5F5">
                    <th style="width: 90%">Categories</th>
                    <th style="border-left: none"><i class="icon-th-list"></i></th>
                </tr>
            </thead>
            <tbody>
                <tr id="0">
                    <td style="color: #127BC0">
                        <b>
                            @Ajax.ActionLink("All Discussions", "Index", "Discussion", new { }, new AjaxOptions { UpdateTargetId = "list", InsertionMode = InsertionMode.Replace })
                        </b>
                    </td>
                    <td style="border-left: none; border-bottom: none">
                        <b>@Model.Count</b>
                    </td>
                </tr>
                <tr>
                    <td colspan="2">
                        <div style="padding-left: 10px">
                            <table class="table table-hover">
                                @for (var i = 0; i < @ViewBag.Subject.Count; i++)
                                {
                                    <tr id="@ViewBag.Subject[i].SubjectId">
                                        <td style="color: #127BC0; border: none">
                                            <b>
                                                @Ajax.ActionLink("+ " + (string) @ViewBag.Subject[i].Code, "Index", "Discussion", new {subjectId = @ViewBag.Subject[i].SubjectId}, new AjaxOptions {UpdateTargetId = "list", InsertionMode = InsertionMode.Replace}, new {@class = @ViewBag.Subject[i].SubjectId})
                                            </b>
                                        </td>
                                        @*<td style="border-top: none">
                                            <b>@ViewBag.Count[i]</b>
                                        </td>*@
                                    </tr>
                                }
                            </table>
                        </div>
                    </td>
                </tr>
            </tbody>
        </table>
    </div>
    <div id="unobtrusive" class="span12">
        @Html.Partial("_List")
    </div>
</div>